"use strict";
cc._RF.push(module, '09a8dd3kW1BP4PeCZjQ7mJo', 'ScreenShotNode');
// scripts/ScreenShotNode.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});
var r = t("GlobalUserData"),
    s = cc._decorator,
    l = s.ccclass,
    c = (s.property, function (t) {
  function e() {
    return null !== t && t.apply(this, arguments) || this;
  }

  var o;
  return n(e, t), o = e, e.prototype.onLoad = function () {
    o._inst = this;
    var t = this.getComponent(cc.Camera);
    t || (t = this.addComponent(cc.Camera)), t.enabled = !1;
    var e = cc.winSize.width,
        i = cc.winSize.height,
        n = cc.size(1 * e, 1 * i),
        a = cc.v2(0, 0);
    t.zoomRatio = 1;
    var r = new cc.RenderTexture();
    t.cullingMask = 4294967295;
    var s = cc.game._renderContext;
    r.initWithSize(n.width, n.height, s.STENCIL_INDEX8), this.node.setPosition(a), t.targetTexture = r, this._camera = t, this._texture = r;
  }, e.prototype.shot = function () {
    console.log("截屏"), this._camera.render(void 0);
  }, e.processData = function () {
    var t = o._inst._texture,
        e = t.readPixels(),
        i = t.width,
        n = t.height,
        a = document.createElement("canvas"),
        r = a.getContext("2d");
    a.width = i, a.height = n;

    for (var s = 4 * i, l = 0; l < n; l++) {
      for (var c = n - 1 - l, d = r.createImageData(i, 1), h = c * i * 4, p = 0; p < s; p++) {
        d.data[p] = e[h + p];
      }

      r.putImageData(d, 0, l);
    }

    var u = a.toDataURL("image/jpeg");

    o._inst.loadTexture(u);
  }, e.prototype.loadTexture = function (t) {
    var e = new Image();
    e.src = t, e.onload = function () {
      var t = new cc.Texture2D();
      t.initWithElement(e), t.handleLoadedTexture(), r["default"].screenShotSF && r["default"].screenShotSF.destroy(), r["default"].screenShotSF = new cc.SpriteFrame(t);
    };
  }, e.prototype.downloadImg = function (t) {
    var e = t.replace(/^data:image[^;]*/, "data:image/octet-stream");
    document.location.href = e;
  }, e.take = function () {
    o._inst.shot();
  }, o = a([l], e);
}(cc.Component));
o["default"] = c;

cc._RF.pop();